#include "music.h"

#ifndef SKYID_DISABLE_SOUND
namespace SkyID
{

//- Music ---------------------------------------------------------------------

Music::Music() :
	mReader(NULL)
{
	//
}

Music::~Music()
{
	delete mReader;
	mReader = NULL;
}

bool Music::update()
{
	if (!isPlaying())
		return false;

	ALint processed;
	ALuint buffer;
	alGetSourcei(mID, AL_BUFFERS_PROCESSED, &processed);

	while (processed--)
	{
		alSourceUnqueueBuffers(mID, 1, &buffer);
		fillBuffer(buffer);
		alSourceQueueBuffers(mID, 1, &buffer);
	}

	return true;
}

void Music::cleanBuffer()
{
	ALint queued;
	ALuint buffer;
	alGetSourcei(mID, AL_BUFFERS_QUEUED, &queued);

	while (queued--)
	{
		alSourceUnqueueBuffers(mID, 1, &buffer);
		check();
	}
}

} // namespace SkyID
#endif // SKYID_DISABLE_SOUND
